// SMSQueue.cpp: implementation of the CSMSQueue class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "log4cplus_switch.h"
#include <string>
#include <list>
#include <map>
#include "SMSQueue.h"
#include "Account.h"
#include "AccountManager.h"


LOG4CPLUS_CLASS_IMPLEMENT( CSMSQueue, _s_logger, "CSMSQueue" );

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CSMSQueue::CSMSQueue()
{
    m_pParent = NULL;
}

CSMSQueue::~CSMSQueue()
{

}

void CSMSQueue::SendOut()    //Send out SMS by IF's send function
{
	//1 first check whether the sending map is full
	//2 if no , begin send sms to the IF
	//3 if send succ, then add the sms to sending map
	while(m_SendingMap.size() < 100 && m_WaittingList.size()>0)
	{
		std::list<CSMSItem*>::iterator it;
		it=m_WaittingList.begin();
		CSMSItem* pSMS = *it;
		
		//Get SeqNo from IF
		//send sms out by account's IF
		if(GetParent()->SendOutByIF(pSMS))
		{
			m_WaittingList.pop_front();
			//m_SendingMap[] = pSMS;
		}
		else
		{
			//exit while
			break;
		}
	}
}
void CSMSQueue::SetParent(CAccount* p)
{
	m_pParent =p;
}
CAccount* CSMSQueue::GetParent()
{
	return m_pParent;
}
